{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 3, 6, 10, 2, 5, 9, 3, 7, 4]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 3, 4, 5, 6, 7, 9, 10]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import itertools\n",
    "\n",
    "def continous_sub_lists (xs): \n",
    "    n = len(xs)\n",
    "    indices = list(range(n+1))\n",
    "    for i,j in itertools.combinations(indices,2):\n",
    "        yield sum(xs[i:j])\n",
    "print(list(continous_sub_lists([1,2,3,4])))\n",
    "sorted(list(continous_sub_lists([1,2,3,4])))\n",
    "#1, 3, 6, 10, 2, 5, 9, 3, 7, 4\n",
    "#1, 2, 3, 3, 4, 5, 6, 7, 9, 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import itertools\n",
    "\n",
    "class Solution:\n",
    "    def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int:\n",
    "        def continous_sub_lists (xs): \n",
    "            n = len(xs)\n",
    "            indices = list(range(n+1))\n",
    "            for i,j in itertools.combinations(indices,2):\n",
    "                yield sum(xs[i:j])\n",
    "        elements = list(continous_sub_lists(nums))\n",
    "        elements.sort()\n",
    "        print(elements)\n",
    "        print(elements[left-1:right])\n",
    "        return sum(elements[left-1:right]) % 1000000007"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 3, 4, 5, 6, 7, 9, 10]\n",
      "[1, 2, 3, 3, 4]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "13"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = Solution()\n",
    "s.rangeSum([1,2,3,4], 4, 1, 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "16716700000 % (10^9 + 7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "716699888"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "16716700000 % (10**9 + 7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000000007"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "10**9 + 7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "716699888"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "16716700000 % 1000000007"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "716699888"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/range-sum-of-sorted-subarray-sums/\n",
    "\n",
    "\n",
    "Runtime: 5212 ms, faster than 5.29% of Python3 online submissions for Range Sum of Sorted Subarray Sums.\n",
    "\n",
    "Memory Usage: 44.3 MB, less than 5.08% of Python3 online submissions for Range Sum of Sorted Subarray Sums.\n",
    "\n",
    "\n",
    "```python\n",
    "from typing import List\n",
    "import itertools\n",
    "\n",
    "class Solution:\n",
    "    def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int:\n",
    "        def continous_sub_lists (xs): \n",
    "            n = len(xs)\n",
    "            indices = list(range(n+1))\n",
    "            for i,j in itertools.combinations(indices,2):\n",
    "                yield sum(xs[i:j])\n",
    "        elements = list(continous_sub_lists(nums))\n",
    "        elements.sort()\n",
    "        print(elements)\n",
    "        print(elements[left-1:right])\n",
    "        return sum(elements[left-1:right]) % 1000000007\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
